<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>供应商管理</title>
    <script type="text/javascript" src="static/jquery-easyui/jquery.min.js"></script>
    <script type="text/javascript" src="static/jquery-easyui/jquery.easyui.min.js"></script>
    <link type="text/css" rel="stylesheet" href="static/css/comm.css"/>
    <link type="text/css" rel="stylesheet" href="static/jquery-easyui/themes/default/easyui.css">
    <link type="text/css" rel="stylesheet" href="static/jquery-easyui/themes/icon.css">
    <script type="text/javascript" src="static/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>

</head>
<body>
<div class="easyui-layout" data-options="fit:true">

    <div class="inner-content" data-options="region:'center'" style="height: 50%">
        <!-- 数据表 -->
        <table class="easyui-datagrid" title="商家列表" fit="true" fitColumns="true"
               toolbar="#libraryTool"
               striped="true" rownumbers="true" pagination="true" remoteSort="false" id="libraryTg">

        </table>
        <!-- /数据表 -->

        <!-- 数据表工具栏 -->
        <div class="toolbar" id="libraryTool">
            <div class="search-div">
                <label>用户编号：</label>
                <input type="text" class="easyui-textbox" id="library_Id"/>
                <label>用户名称：</label>
                <input type="text" class="easyui-textbox" id="libraryName"/>
                <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchLibrary">搜索</a>
            </div>
            <div class="ctrl-div">
                <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="libraryAdd">新增</a>
                <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" id="libraryUpate">编辑</a>
                <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" id="multLibraryDelete">批量删除</a>
            </div>
        </div>
        <!-- /数据表工具栏 -->
    </div>

    <div region="south" id="footer" style="height: 50%">
        <!-- 数据表 -->
        <table class="easyui-datagrid" title="商家图书种类列表" fit="true" fitColumns="true"
               toolbar="#libraryBookTool"
               striped="true" rownumbers="true"  remoteSort="false" pagination="true" id="libraryBookTg">

        </table>

        <!-- 数据表工具栏 -->
        <div class="toolbar" id="libraryBookTool">
            <div class="search-div">
                <label>图书种类编号：</label>
                <input type="text" class="easyui-textbox" id="libraryBookId"/>
                <label>图书种类名称：</label>
                <input type="text" class="easyui-textbox" id="libraryBookName"/>
                <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchLibraryBook">搜索</a>
            </div>
        </div>
        <!-- /数据表工具栏 -->

    </div>

    <!--商家添加-->
    <div id="libraryDivId" class="easyui-dialog" title="商家添加"  style="width: 400px; padding: 10px 20px; height: 350px;"
         closed="true" buttons="#library-buttons">
        <form id="libraryForm" method="post">
            <table cellpadding="5">
                <tr>
                    <td>ID:</td>
                    <td><input id="libraryId" class="easyui-textbox" type="text" name="libraryId" data-options="required:true" validType='length[8,12]'></input></td>
                </tr>
                <tr>
                    <td>Name:</td>
                    <td><input class="easyui-textbox" type="text" name="libraryName" data-options="required:true" validType='length[3,10]'></input></td>
                </tr>
                <tr>
                    <td>Address:</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="libraryAddress" data-options="required:true"></input>
                    </td>
                </tr>
                <tr>
                    <td>Code:</td>
                    <td><input class="easyui-textbox" type="text" name="libraryCode" data-options="required:true" validType='ZIP'></input></td>
                </tr>
                </tr>
            </table>
            <div id="library-buttons" style="display: block">
                <a id="confirm" href="javascript:void(0)" class="easyui-linkbutton c6" iconcls="icon-ok" onclick="submitLibraryForm()" style="width: 90px">提交</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#libraryDivId').dialog('close')" style="width: 90px">取消</a>
            </div>
        </form>
    </div>
</div>


<script type="text/javascript">
    var temp=true;
    var bookId;
    $(function () {
        ajaxDatagrid();
    });

    $.extend($.fn.validatebox.defaults.rules, {
        CHS: {
            validator: function (value, param) {
                return /^[\u0391-\uFFE5]+$/.test(value);
            },
            message: '请输入汉字'
        },
        english : {// 验证英语
            validator : function(value) {
                return /^[A-Za-z]+$/i.test(value);
            },
            message : '请输入英文'
        },
        ip : {// 验证IP地址
            validator : function(value) {
                return /\d+\.\d+\.\d+\.\d+/.test(value);
            },
            message : 'IP地址格式不正确'
        },
        ZIP: {
            validator: function (value, param) {
                return /^[0-9]\d{5}$/.test(value);
            },
            message: '邮政编码不存在'
        },
        QQ: {
            validator: function (value, param) {
                return /^[1-9]\d{4,10}$/.test(value);
            },
            message: 'QQ号码不正确'
        },
        mobile: {
            validator: function (value, param) {
                return /^(?:13\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/.test(value);
            },
            message: '手机号码不正确'
        },
        tel:{
            validator:function(value,param){
                return /^(\d{3}-|\d{4}-)?(\d{8}|\d{7})?(-\d{1,6})?$/.test(value);
            },
            message:'电话号码不正确'
        },
        mobileAndTel: {
            validator: function (value, param) {
                return /(^([0\+]\d{2,3})\d{3,4}\-\d{3,8}$)|(^([0\+]\d{2,3})\d{3,4}\d{3,8}$)|(^([0\+]\d{2,3}){0,1}13\d{9}$)|(^\d{3,4}\d{3,8}$)|(^\d{3,4}\-\d{3,8}$)/.test(value);
            },
            message: '请正确输入电话号码'
        },
        number: {
            validator: function (value, param) {
                return /^[0-9]+.?[0-9]*$/.test(value);
            },
            message: '请输入数字'
        },
        money:{
            validator: function (value, param) {
                return (/^(([1-9]\d*)|\d)(\.\d{1,2})?$/).test(value);
            },
            message:'请输入正确的金额'

        },
        mone:{
            validator: function (value, param) {
                return (/^(([1-9]\d*)|\d)(\.\d{1,2})?$/).test(value);
            },
            message:'请输入整数或小数'

        },
        integer:{
            validator:function(value,param){
                return /^[+]?[1-9]\d*$/.test(value);
            },
            message: '请输入最小为1的整数'
        },
        integ:{
            validator:function(value,param){
                return /^[+]?[0-9]\d*$/.test(value);
            },
            message: '请输入整数'
        },
        range:{
            validator:function(value,param){
                if(/^[1-9]\d*$/.test(value)){
                    return value >= param[0] && value <= param[1]
                }else{
                    return false;
                }
            },
            message:'输入的数字在{0}到{1}之间'
        },
        minLength:{
            validator:function(value,param){
                return value.length >=param[0]
            },
            message:'至少输入{0}个字'
        },
        maxLength:{
            validator:function(value,param){
                return value.length<=param[0]
            },
            message:'最多{0}个字'
        },
        //select即选择框的验证
        selectValid:{
            validator:function(value,param){
                if(value == param[0]){
                    return false;
                }else{
                    return true ;
                }
            },
            message:'请选择'
        },
        idCode:{
            validator:function(value,param){
                return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value);
            },
            message: '请输入正确的身份证号'
        },
        loginName: {
            validator: function (value, param) {
                return /^[\u0391-\uFFE5\w]+$/.test(value);
            },
            message: '登录名称只允许汉字、英文字母、数字及下划线。'
        },
        equalTo: {
            validator: function (value, param) {
                return value == $(param[0]).val();
            },
            message: '两次输入的字符不一至'
        },
        englishOrNum : {// 只能输入英文和数字
            validator : function(value) {
                return /^[a-zA-Z0-9_ ]{1,}$/.test(value);
            },
            message : '请输入英文、数字、下划线或者空格'
        },
        xiaoshu:{
            validator : function(value){
                return /^(([1-9]+)|([0-9]+\.[0-9]{1,2}))$/.test(value);
            },
            message : '最多保留两位小数！'
        },
        ddPrice:{
            validator:function(value,param){
                if(/^[1-9]\d*$/.test(value)){
                    return value >= param[0] && value <= param[1];
                }else{
                    return false;
                }
            },
            message:'请输入1到100之间正整数'
        },
        jretailUpperLimit:{
            validator:function(value,param){
                if(/^[0-9]+([.]{1}[0-9]{1,2})?$/.test(value)){
                    return parseFloat(value) > parseFloat(param[0]) && parseFloat(value) <= parseFloat(param[1]);
                }else{
                    return false;
                }
            },
            message:'请输入0到100之间的最多俩位小数的数字'
        },
        rateCheck:{
            validator:function(value,param){
                if(/^[0-9]+([.]{1}[0-9]{1,2})?$/.test(value)){
                    return parseFloat(value) > parseFloat(param[0]) && parseFloat(value) <= parseFloat(param[1]);
                }else{
                    return false;
                }
            },
            message:'请输入0到1000之间的最多俩位小数的数字'
        }
    });

    function ajaxDatagrid() {
        $('#libraryTg').datagrid({
            url:'selectLibraryAll',
            columns:[[
                {title: '全选', field: 'ck',checkbox : true, sortable: false},
                {field:'libraryId',align:'center',title:'创库ID',width:100},
                {field:'libraryName',align:'center',title:'创库名称',width:100},
                {field:'libraryAddress',align:'center',title:'创库地址',width:100},
                {field:'libraryCode',align:'center',title:'创库编码',width:100},
                {field:'libraryCreattime',align:'center',title:'创建时间',formatter:formatDatebox,width:100},
            ]],
            fitColumns:true,
            //pagination:true,
            rowNumbers:true,
            singleSelect: false,
            onDblClickRow :function(rowIndex,rowData){
                bookId=rowData.libraryId;
               // alert("双击"+rowData.libraryId);
                ajaxBookManager(rowData.libraryId);
            }
        });
    }

    function formatDatebox(milliseconds) {
        if (milliseconds != "" && milliseconds != null
            && milliseconds != "null") {
            var datetime = new Date();
            datetime.setTime(milliseconds);
            var year = datetime.getFullYear();
            var month = datetime.getMonth() + 1 < 10 ? "0"
                + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
            var date = datetime.getDate() < 10 ? "0" + datetime.getDate()
                : datetime.getDate();
            var hour = datetime.getHours() < 10 ? "0" + datetime.getHours()
                : datetime.getHours();
            var minute = datetime.getMinutes() < 10 ? "0"
                + datetime.getMinutes() : datetime.getMinutes();
            var second = datetime.getSeconds() < 10 ? "0"
                + datetime.getSeconds() : datetime.getSeconds();
            return year + "-" + month + "-" + date + " " + hour + ":" + minute
                + ":" + second;
        } else {
            return "";
        }
    }

    $('#libraryAdd').linkbutton({
        onClick:function () {
            temp = true;
            $('#libraryDivId').form('clear');
            $('#libraryDivId').dialog({
                closed:false,
                cache:false,
                modal:true,
                title:"商家添加",
            });
            $('#libraryId').textbox({
                editable:true,
            });
        }
    });

    function submitLibraryForm() {
        if (temp ==true){
            var v=$('#libraryDivId').form('validate');
            if (v){
                $.ajax({
                    url:'libraryAdd',
                    type:'POST',
                    data:$('#libraryForm').serialize(),
                    success:function (result) {
                        $.messager.alert("提示","添加成功","info");
                        $('#libraryDivId').dialog('close',true);
                        ajaxDatagrid();
                    },
                    error:function (result) {
                        $.messager.alert("提示","添加失败","info");
                    }
                });
            }else{
                $.messager.alert("提示","请填写相关数据!","info");
            }

        }else{
            $.ajax({
                type:"POST",
                url:'library/update',
                data:$('#libraryForm').serialize(),
                success:function (result) {
                    $.messager.alert("提示信息","操作成功!","info");
                    $('#libraryDivId').dialog('close',true);
                    ajaxDatagrid();
                },
                error:function (result) {
                    $.messager.alert("提示信息","操作失败!","info");
                    $('#libraryDivId').dialog('close',true);
                }
            });
        }
    }

    $('#libraryUpate').linkbutton({
        onClick:function () {
            temp=false;
            var len=$('#libraryTg').datagrid('getSelections').length;
            if (len ==1){
                var rows=$('#libraryTg').datagrid('getSelected').libraryId;
                libraryUpate(rows);
            }else{
                $.messager.alert("提示","请选择一行需要修改的数据!","info");
            }
            $('#libraryId').textbox({
                editable:false,
            });

        }
    });

    function libraryUpate(id) {
        $.ajax({
            url: 'findLibraryById',
            data: {"id": id},
            type: 'POST',
            success: function (result) {
                $('#libraryDivId').dialog({
                    closed: false,
                    cache: false,
                    modal: true,
                    title: "商家修改",
                });
                $('#libraryDivId').form('clear');
                $('#libraryDivId').form('load', {
                    libraryId: result.data.libraryId,
                    libraryName: result.data.libraryName,
                    libraryAddress:result.data.libraryAddress,
                    libraryCode: result.data.libraryCode,
                });

            }
        });
    }

    $('#multLibraryDelete').linkbutton({
       onClick:function () {
           var arry=[];
           var len=$('#libraryTg').datagrid('getSelections');
           if (len ==0){
               $.messager.alert("提示","请选择一行或者多行删除","info");
           }else{

               for (var i=0;i<len.length;i++){
                   arry.push(len[i].libraryId);
               }
               $.messager.confirm("提示","确定要删除吗?",function (flag) {
                   if (flag){
                       $.ajax({
                           url:'multDeleteUserInfo' ,
                           type:'POST',
                           data:{multId:arry},
                           traditional:true,
                           success:function (result) {
                               $.messager.alert("提示","删除成功","info");
                               ajaxDatagrid();
                           }
                           ,
                           error:function (result) {
                               $.messager.alert("提示","删除失败","info");
                           }
                       });
                   }else {
                       return ;
                   }
               });
           }
       }
    });

    $('#searchLibrary').linkbutton({
       onClick:function () {
           var arry=[];
           var library_Id=$('#library_Id').textbox('getValue');
           var libraryName=$('#libraryName').textbox('getValue');
                   $.ajax({
                       url:'expFindLibraryInfo' ,
                       type:'POST',
                       data:{"library_Id":library_Id,"libraryName":libraryName},
                       success:function (result) {
                           $.messager.alert("提示","查询成功","info");
                           $('#libraryTg').datagrid('loadData',result.data);
                       }
                       ,
                       error:function (result) {
                           $.messager.alert("提示","查询失败","info");
                       }
                   });
               }


    });

    function ajaxBookManager(id) {
        $('#libraryBookTg').datagrid({
            url:'findBookManager/'+id,
            columns:[[
                {title: '全选', field: 'ck',checkbox : true, sortable: false},
                {field:'bId',align:'center',title:'图书种类ID',width:100},
                {field:'bName',align:'center',title:'图书种类名称',width:100},
                {field:'bState',align:'center',title:'图书种类状态',formatter:meupdate,width:100},
                {field:'bCount',align:'center',title:'图书种类数量',width:100},
                {field:'bMsg',align:'center',title:'图书种类描述',width:100},
            ]],
            fitColumns:true,
            rowNumbers:true,
            singleSelect: false,
        });
    }
    function meupdate(text) {
        if (text=='0'){
            return "下架";
        }else{
            return "上架";
        }
    }

    $('#searchLibraryBook').linkbutton({
        onClick:function () {
            var libraryBookId=$('#libraryBookId').textbox('getValue');
            var libraryBookName=$('#libraryBookName').textbox('getValue');
                    $.ajax({
                        url:'searchLibraryBook' ,
                        type:'POST',
                        data:{"id":bookId,"libraryBookId":libraryBookId,"libraryBookName":libraryBookName},
                        success:function (result) {
                            $.messager.alert("提示","查询成功","info");
                            $('#libraryBookTg').datagrid('loadData',result.data);
                        }
                        ,
                        error:function (result) {
                            $.messager.alert("提示","查询失败","info");
                        }
                    });
                }
    });

</script>
</body>
</html>